﻿#ifdef _WIN32
#include "windows_defines.h"
#endif
#include "../../../../../../unittest/framework/unittest.hh"
#include "util/timer_wheel.hh"


FIXTURE_BEGIN(test_memory)

SETUP([]() {
})

CASE(TestMemory1) {
    kratos::util::TimerWheel tw(nullptr);
    bool done = false;
    int count = 0;
    kratos::util::TimerID id;
    ASSERT_TRUE(id = tw.schedule(
                    [&](kratos::util::TimerID, std::uint64_t) -> bool {
                        done = true;
                        count += 1;
                        tw.cancel(id);
                        return true;
                    },
                    500, 0));
    auto start = kratos::util::get_os_time_millionsecond();
    while (true)
    {
        auto now = kratos::util::get_os_time_millionsecond();
        tw.update(now);
        if (now - start > 1100)
        {
            break;
        }
    }
    ASSERT_TRUE(done);
    ASSERT_TRUE(count == 1);
}

FIXTURE_END(test_memory)